package com.agger.harmonyosthemeseditor.userinterface;

import com.agger.harmonyosthemeseditor.ResourceTable;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.ComponentState;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.components.element.StateElement;
import ohos.app.Context;

public class GeneralButtonElement extends StateElement{
    private Context mContext;

    private int[] mStateFlagEmpty = new int[] {ComponentState.COMPONENT_STATE_EMPTY};

    private int[] mStateFlagPressed = new int[] {ComponentState.COMPONENT_STATE_PRESSED};

    private int[][] mAllTypeColorIds = {{ResourceTable.Color_dawnlighti_button_normal,ResourceTable.Color_dawnlighti_button_normal_pressed_dialog},{ResourceTable.Color_dawnlighti_button_accent,ResourceTable.Color_dawnlighti_button_accent_pressed_dialog},{ResourceTable.Color_dawnlighti_button_error,ResourceTable.Color_dawnlighti_button_error_pressed_dialog}};

    public static final int TYPE_NORMAL = 0;

    public static final int TYPE_ACCENT = 1;

    public static final int TYPE_ERROR = 2;

    public static final int TYPE_UI_Button = 3;

    public static final int TYPE_Empty_Button = 4;

    public GeneralButtonElement(Context context, int type)
    {
        super();
        mContext = context;
        if(type < 3)
        initBackground(mAllTypeColorIds[type]);
        else
        {
            if(type == TYPE_UI_Button)
            initBackground_UI_Button();
            else if(type == TYPE_Empty_Button)
                initBackground_Empty_Button();
        }
    }

    private void initBackground(int[] colorIds)
    {
        this.addState(mStateFlagPressed, new ShapeElement()
        {
            {
                setRgbColor(RgbColor.fromArgbInt(ResourceTool.getColor(mContext, colorIds[1], 0)));
                setCornerRadius(ResourceTool.getFloat(mContext, ResourceTable.Float_dialog_corner_radius, 0));
            }
        });
        this.addState(mStateFlagEmpty, new ShapeElement()
        {
            {
                setRgbColor(RgbColor.fromArgbInt(ResourceTool.getColor(mContext, colorIds[0], 0)));
                setCornerRadius(ResourceTool.getFloat(mContext, ResourceTable.Float_dialog_corner_radius, 0));
            }
        });
    }

    private void initBackground_UI_Button()
    {
        this.addState(mStateFlagPressed, new ShapeElement()
        {
            {
                setRgbColor(RgbColor.fromArgbInt(ResourceTool.getColor(mContext, ResourceTable.Color_dawnlighti_button_accent_pressed, 0)));
                setCornerRadius(ResourceTool.getFloat(mContext, ResourceTable.Float_ui_button_corner_radius, 0));
            }
        });
        this.addState(mStateFlagEmpty, new ShapeElement()
        {
            {
                setRgbColor(RgbColor.fromArgbInt(ResourceTool.getColor(mContext, ResourceTable.Color_dawnlighti_button_accent, 0)));
                setCornerRadius(ResourceTool.getFloat(mContext, ResourceTable.Float_ui_button_corner_radius, 0));
            }
        });
    }

    private void initBackground_Empty_Button()
    {
        this.addState(mStateFlagPressed, new ShapeElement()
        {
            {
                setRgbColor(RgbColor.fromArgbInt(ResourceTool.getColor(mContext, ResourceTable.Color_dawnlighti_button_empty_pressed, 0)));
                setCornerRadius(ResourceTool.getFloat(mContext, ResourceTable.Float_empty_button_corner_radius, 0));
            }
        });
        this.addState(mStateFlagEmpty, new ShapeElement()
        {
            {
                setRgbColor(RgbColor.fromArgbInt(ResourceTool.getColor(mContext, ResourceTable.Color_dawnlighti_button_empty, 0)));
                setCornerRadius(ResourceTool.getFloat(mContext, ResourceTable.Float_empty_button_corner_radius, 0));
            }
        });
    }
}